<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>出勤记录统计</title>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
    <script>

        $(document).ready(function () {


            $("#btn").click(function () {

                // console.log($("#chatlog").val());
                var chatlog = $("#chatlog").val();
                var result = "";
                var duplicate = new Array();

                var needDuplicate = $("#duplicate").val();
                if ($("#QQ")[0].checked) {
                    myregexp = /(?<name>.+) (?<date>\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2})/g;
                } else {
                    myregexp = /(.+?):(.?)/g;
                }

                var match = myregexp.exec(chatlog);
                var i = 1;
                while (match != null) {
                    if (!$("#duplicate")[0].checked) {
                        result += i++ + "," + match[1] + "," + match[2] + "\n";
                    } else {
                        if (duplicate.indexOf(match[1]) < 0) {
                            duplicate.push(match[1]);
                            result += i++ + "," + match[1] + "," + match[2] + "\n";
                        }
                    }

                    match = myregexp.exec(chatlog);
                }
                $("#chatresult").val(result);
            });
        });
    </script>
</head>

<body>

    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <label class="radio-inline">
                    <input type="radio" name="datatype" id="QQ" value="QQ" checked> QQ
                </label>
                <label class="radio-inline">
                    <input type="radio" name="datatype" id="WeChat" value="WeChat"> WeChat
                </label>
                <label class="radio-inline">
                    <input type="checkbox" name="" id="duplicate" value="duplicate"> 剔除重复项
                </label>
                <button class="btn btn-primary" id="btn">解析</button>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">聊天记录：</div>
            <div class="col-sm-12">
                <textarea id="chatlog" cols="100" rows="10"></textarea>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">解析结果：</div>
            <div class="col-sm-12">
                <textarea id="chatresult" cols="100" rows="10"></textarea>
            </div>
        </div>
    </div>


</body>

</html>